package com.mall.shopping.converter;

import com.mall.shopping.dal.entitys.Item;
import com.mall.shopping.dto.ProductDetailDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * @User: Yr
 * @Date: 2021/12/13
 * @Description:
 */

@Mapper(componentModel = "spring")
public interface ProductDetailConverter {

    @Mappings({
        @Mapping(source = "id", target = "productId"),
        @Mapping(source = "price", target = "salePrice"),
        @Mapping(source = "title", target = "productName"),
        @Mapping(source = "sellPoint", target = "subTitle"),
        @Mapping(source = "imageBig", target = "productImageBig"),
        @Mapping(target = "productImageSmall" ,expression = "java(getConverter(item.getImage()))")
//        @Mapping(source = "", target = "detail"),
    })
    ProductDetailDto item2Dto(Item item);

    List<ProductDetailDto> items2Dto(List<Item> items);

    default String[] getConverter(String image){
        String[] split = image.split(",");
        return split;
    }

}
